package com.zyh.em.update;

import com.zyh.em.entity.HistoryData;
import com.zyh.em.entity.LoginSuccessData;

import java.util.ArrayList;
import java.util.List;

public class InputFeaturesUpdate extends AbstractUpdate{
    private int threshold;

    public InputFeaturesUpdate(int threshold) {
        this.threshold = threshold;
    }

    @Override
    public void update(LoginSuccessData loginSuccessData, HistoryData historyData, UpdateChain updateChain) {
        double[] inputFeatures = loginSuccessData.getInputFeatures();
        List<double[]> list = historyData.getInputFeatures();
        if(list==null){
            list = new ArrayList<>();
            historyData.setInputFeatures(list);
        }

        list.add(inputFeatures);
        if(list.size()>threshold){
            list.remove(0);
        }

        updateChain.doUpdate(loginSuccessData, historyData);
    }
}